// wtkwm.hpp
//

#ifndef _WTKWM_HPP
#define _WTKWM_HPP

#include "wtk/wtkbase.hpp"
#include "wtk/wtkevent.hpp"

namespace wtk
{
  class Application;
  class Display;


  
  // WM
  //
  class WTK_API WM
  {
    friend Application;
    
  public:
    WM ();
    ~WM ();

    static WM &get () { WTK_ASSERT(current_wm); return *current_wm; }
    
    bool poll_events ();
    void update ();

  private:
    static WM *current_wm;
    
    // key = window ID
    std::unordered_map<Uint32, Display *> registered_displays;

    Widget *fly_widget{};
    
    void register_display ( Display &display );
    void unregister_display ( Display &display );
    
    void set_fly_widget ( Widget *widget );
    
    void emit_event ( const Event &event );
    
    void handle_key_down ( SDL_KeyboardEvent &sdl_event);
    void handle_key_up ( SDL_KeyboardEvent &sdl_event);
    void handle_mouse_motion ( SDL_MouseMotionEvent &sdl_event );
    void handle_mouse_button ( SDL_MouseButtonEvent &sdl_event,
                               EventType type );
    void handle_mouse_wheel ( SDL_MouseWheelEvent &sdl_event );
  };

  inline WM *WM::current_wm{nullptr};
}

#endif
